import java.util.Scanner;

public class code1 {
    //Fibonacci数列
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = 0,b = 1, c= 1;
        while(a+b<=n) {
            c = a+b;
            a = b;
            b = c;
        }
        System.out.print(Math.min(n-b,a+b-n));
    }
}
